﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Smartmanufact
{
    public partial class Xiadan : Form
    {
        public string id = "";
        public string user = MainView.username;
        public Xiadan()
        {
            InitializeComponent();
            Set_ID();
            Show_User();
            Set_cargo_type();
            Set_Customer();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Dispose();
        }

        private void Xiadan_Load(object sender, EventArgs e)
        {
            
        }

        private void Set_ID()
        {
            label_ID.Text = id;
        }

        private void Show_User()
        {
            label2_username.Text = user;
        }

        private void Set_cargo_type()
        {
            // 添加货物种类下拉菜单
            DataSet ds = MainView.mysql.sql_search_database("select * from cargoinfotable");
            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                comboBox_cargokind.Items.Add(ds.Tables[0].Rows[i][0].ToString());
            }
        }

        private void Set_Customer()
        {
            // 添加客户下拉菜单
            DataSet ds = MainView.mysql.sql_search_database("Select * from customertable");
            int  count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                comboBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
            }
        }

        private void comboBox_cargokind_TextChanged(object sender, EventArgs e)
        {
            // 当货物种类变化时，读取货物名称
            try
            {
                string cargo_id = comboBox_cargokind.Text;
                DataSet ds = MainView.mysql.sql_search_database("Select * from cargoinfotable where cargoinfoID='" + cargo_id + "'");
                label_cargo_name.Text = ds.Tables[0].Rows[0][1].ToString();
            }
            catch { }
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                string customer_id = comboBox1.Text;
                DataSet ds = MainView.mysql.sql_search_database("Select * from customertable where customerID='"+customer_id+"'");
                label_customername.Text = ds.Tables[0].Rows[0][1].ToString();
                label_company.Text = ds.Tables[0].Rows[0][2].ToString();
            }
            catch { }
        }
    }
}
